home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gas / gassrc04.zoo / read.c < prev    next >
C/C++ Source or Header  |  1993-03-02  |  56KB  |  2,098 lines

  1. /* read.c - read a source file -
  2.    Copyright (C) 1986,1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #define MASK_CHAR (0xFF)    /* If your chars aren't 8 bits, you will
  21.                    change this a bit.  But then, GNU isn't
  22.                    spozed to run on your machine anyway.
  23.                    (RMS is so shortsighted sometimes.)
  24.                  */
  25.  
  26. #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
  27.                 /* This is the largest known floating point */
  28.                 /* format (for now). It will grow when we */
  29.                 /* do 4361 style flonums. */
  30.  
  31.  
  32. /* Routines that read assembler source text to build spagetti in memory. */
  33. /* Another group of these functions is in the as-expr.c module */
  34.  
  35. #include <ctype.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include "as.h"
  39. #include "read.h"
  40. #include "md.h"
  41. #include "hash.h"
  42. #include "obstack.h"
  43. #include "frags.h"
  44. #include "flonum.h"
  45. #include "struc-symbol.h"
  46. #include "expr.h"
  47. #include "symbols.h"
  48.  
  49. #ifdef SPARC
  50. #include "sparc.h"
  51. #define OTHER_ALIGN
  52. #endif
  53. #ifdef I860
  54. #include "i860.h"
  55. #endif
  56.  
  57. char *    input_line_pointer;    /* -> next char of source file to parse. */
  58.  
  59.  
  60. #if BITS_PER_CHAR != 8
  61. The following table is indexed by [ (char) ] and will break if
  62. a char does not have exactly 256 states (hopefully 0:255!) !
  63. #endif
  64.  
  65. const char                /* used by is_... macros. our ctype[] */
  66. lex_type [256] = {
  67.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* @ABCDEFGHIJKLMNO */
  68.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* PQRSTUVWXYZ[\]^_ */
  69.   0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0,       /* _!"#$%&'()*+,-./ */
  70.   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,       /* 0123456789:;<=>? */
  71.   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,       /* @ABCDEFGHIJKLMNO */
  72.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3,       /* PQRSTUVWXYZ[\]^_ */
  73.   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,       /* `abcdefghijklmno */
  74.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0,       /* pqrstuvwxyz{|}~. */
  75.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  76.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  77.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  78.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  79.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  80.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
  82. };
  83.  
  84.  
  85. /*
  86.  * In: a character.
  87.  * Out: TRUE if this character ends a line.
  88.  */
  89. #define _ (0)
  90. const char is_end_of_line [256] = {
  91.  _, _, _, _, _, _, _, _, _, _,99, _, _, _, _, _, /* @abcdefghijklmno */
  92.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  93.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  94.  _, _, _, _, _, _, _, _, _, _, _,99, _, _, _, _, /* 0123456789:;<=>? */
  95.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  96.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  97.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  98.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  99.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  100.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  101.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  102.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /*                  */
  103.  _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _  /*                  */
  104. };
  105. #undef _
  106.  
  107.                 /* Functions private to this file. */
  108. void            equals();
  109. void            big_cons();
  110. void            cons();
  111. static char*        demand_copy_C_string();
  112. static char*        demand_copy_string();
  113. void            demand_empty_rest_of_line();
  114. void            float_cons();
  115. long int        get_absolute_expression();
  116. static char        get_absolute_expression_and_terminator();
  117. static segT        get_known_segmented_expression();
  118. void            ignore_rest_of_line();
  119. static int        is_it_end_of_statement();
  120. static void        pobegin();
  121. static void        pseudo_set();
  122. static void        stab();
  123. static void        stringer();
  124.  
  125. extern char line_comment_chars[];
  126.  
  127. static char *    buffer_limit;    /* -> 1 + last char in buffer. */
  128.  
  129. static char *    bignum_low;    /* Lowest char of bignum. */
  130. static char *    bignum_limit;    /* 1st illegal address of bignum. */
  131. static char *    bignum_high;    /* Highest char of bignum. */
  132.                 /* May point to (bignum_start-1). */
  133.                 /* Never >= bignum_limit. */
  134. static char *old_buffer = 0;    /* JF a hack */
  135. static char *old_input;
  136. static char *old_limit;
  137.  
  138. #ifndef WORKING_DOT_WORD
  139. struct broken_word *broken_words;
  140. int new_broken_words = 0;
  141. #endif
  142.  
  143. static void grow_bignum ();
  144. static int next_char_of_string ();
  145.  
  146. void
  147. read_begin()
  148. {
  149.   pobegin();
  150.   obstack_begin( ¬es, 5000 );
  151. #define BIGNUM_BEGIN_SIZE (16)
  152.   bignum_low = xmalloc((long)BIGNUM_BEGIN_SIZE);
  153.   bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
  154. }
  155.  
  156. /* set up pseudo-op tables */
  157.  
  158. static struct hash_control *
  159. po_hash = NULL;            /* use before set up: NULL-> address error */
  160.  
  161.  
  162. void    s_abort(),    s_align(),    s_comm(),    s_data();
  163. void    s_desc(),    s_even(),    s_file(),    s_fill();
  164. void    s_globl(),    s_lcomm(),    s_line(),    s_lsym();
  165. void    s_org(),    s_set(),    s_space(),    s_text();
  166. #ifdef VMS
  167. char const_flag = 0;
  168. void s_const();
  169. #endif
  170.  
  171. #ifdef DONTDEF
  172. void    s_gdbline(),    s_gdblinetab();
  173. void    s_gdbbeg(),    s_gdbblock(),    s_gdbend(),    s_gdbsym();
  174. #endif
  175.  
  176. void    stringer();
  177. void    cons();
  178. void    float_cons();
  179. void    big_cons();
  180. void    stab();
  181.  
  182. static const pseudo_typeS
  183. potable[] =
  184. {
  185.   { "abort",    s_abort,    0    },
  186.   { "align",    s_align,    0    },
  187.   { "ascii",    stringer,    0    },
  188.   { "asciz",    stringer,    1    },
  189.   { "byte",    cons,        1    },
  190.   { "comm",    s_comm,        0    },
  191. #ifdef VMS
  192.   { "const",    s_const,    0    },
  193. #endif
  194.   { "data",    s_data,        0    },
  195.   { "desc",    s_desc,        0    },
  196.   { "double",    float_cons,    'd'    },
  197.   { "file",    s_file,        0    },
  198.   { "fill",    s_fill,        0    },
  199.   { "float",    float_cons,    'f'    },
  200. #ifdef DONTDEF
  201.   { "gdbbeg",    s_gdbbeg,    0    },
  202.   { "gdbblock",    s_gdbblock,    0    },
  203.   { "gdbend",    s_gdbend,    0    },
  204.   { "gdbsym",    s_gdbsym,    0    },
  205.   { "gdbline",    s_gdbline,    0    },
  206.   { "gdblinetab",s_gdblinetab,    0    },
  207. #endif
  208.   { "globl",    s_globl,    0    },
  209.   { "int",    cons,        4    },
  210.   { "lcomm",    s_lcomm,    0    },
  211.   { "line",    s_line,        0    },
  212.   { "long",    cons,        4    },
  213.   { "lsym",    s_lsym,        0    },
  214.   { "octa",    big_cons,    16    },
  215.   { "org",    s_org,        0    },
  216.   { "quad",    big_cons,    8    },
  217.   { "set",    s_set,        0    },
  218.   { "short",    cons,        2    },
  219.   { "single",    float_cons,    'f'    },
  220.   { "space",    s_space,    0    },
  221.   { "stabd",    stab,        'd'    },
  222.   { "stabn",    stab,        'n'    },
  223.   { "stabs",    stab,        's'    },
  224.   { "text",    s_text,        0    },
  225. #ifndef SPARC
  226.   { "word",    cons,        2    },
  227. #endif
  228.   { NULL}    /* end sentinel */
  229. };
  230.  
  231. static void
  232. pobegin()
  233. {
  234.   char *    errtxt;        /* error text */
  235.   const pseudo_typeS * pop;
  236.  
  237.   po_hash = hash_new();
  238.   errtxt = "";            /* OK so far */
  239.   for (pop=potable; pop->poc_name && !*errtxt; pop++)
  240.     {
  241.       errtxt = hash_insert (po_hash, pop->poc_name, (char *)pop);
  242.     }
  243.  
  244.   for(pop=md_pseudo_table; pop->poc_name && !*errtxt; pop++)
  245.       errtxt = hash_insert (po_hash, pop->poc_name, (char *)pop);
  246.  
  247.   if (*errtxt)
  248.     {
  249.       as_fatal ("error constructing pseudo-op table");
  250.     }
  251. }                /* pobegin() */
  252.  
  253. /*            read_a_source_file()
  254.  *
  255.  * File has already been opened, and will be closed by our caller.
  256.  *
  257.  * We read the file, putting things into a web that
  258.  * represents what we have been reading.
  259.  */
  260. void
  261. read_a_source_file (buffer)
  262.      char *    buffer;        /* 1st character of each buffer of lines is here. */
  263. {
  264.   register char        c;
  265.   register char *    s;    /* string of symbol, '\0' appended */
  266.   register int        temp;
  267.   /* register struct frag * fragP; JF unused */    /* a frag we just made */
  268.   pseudo_typeS    *pop;
  269. #ifdef DONTDEF
  270.   void gdb_block_beg();
  271.   void gdb_block_position();
  272.   void gdb_block_end();
  273.   void gdb_symbols_fixup()